package service;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author: jie.zhao
 * @create: 2021/03/20 20:41
 */
public class Request {

    private String url;

    private String method;

    private String ip;

    private int port;

    private InputStream inputStream;


    public Request(InputStream inputStream) throws IOException {

        int count = 0;
        while (count==0){
            count = inputStream.available();
        }

        byte[] arr = new byte[count];
        inputStream.read(arr);

        String inputStr = new String(arr);
         String str = inputStr.split("\\n")[0];
        final String[] strings = str.split(" ");
        this.method =  strings[0];
        this.url = strings[1];

        String host = inputStr.split("\\n")[1];
        String[] split = host.split(" ");
        String[] ipPort = split[1].split(":");
        this.ip = ipPort[0];
        this.port = Integer.parseInt(ipPort[1].trim());

    }


    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

}
